//checkBox 复选框
//const Checkbox({
//Key key,
//@required this.value,//当前值，是否选中
//@required this.onChanged,//选中变更监听
//this.activeColor,//选中时的颜色
//})

import 'package:flutter/material.dart';
import 'package:flutter_practice/utils/Utils.dart';

class MyCheckBoxDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MyCheckBoxState();
  }
}

class MyCheckBoxState extends State<MyCheckBoxDemo> {
  var _isCheck = false;

  void _changeState(bool isC) {
    setState(() {
      _isCheck = isC;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Utils.getAppBar('复选框demo'),
      body: Center(
        child: Checkbox(
          value: _isCheck,
          onChanged: _changeState,
        ),
      ),
    );
  }
}

//Radio  单选框
class MyRadioDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MyRadioState();
  }
}

class MyRadioState extends State<MyRadioDemo> {
  int radioValue = 0;

  _handleRadioValue(int values) {
    setState(() {
      radioValue = values;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: Utils.getAppBar('单选框'),
      body: Center(
        child: Column(
          children: <Widget>[
            Radio(
                value: 0, groupValue: radioValue, onChanged: _handleRadioValue),
            Radio(
                value: 1, groupValue: radioValue, onChanged: _handleRadioValue),
            Radio(
                value: 2, groupValue: radioValue, onChanged: _handleRadioValue),
          ],
        ),
      ),
    );
  }
}
//Switch 控制开关
//const Switch({
//Key key,
//@required this.value,
//@required this.onChanged,
//this.activeColor,
//this.activeTrackColor,
//this.inactiveThumbColor,
//this.inactiveTrackColor,
//this.activeThumbImage,
//this.inactiveThumbImage
//})

//Slider
//Slider滑块组件，也类似于进度条组件，

class MySwitchDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MySwitchState();
  }
}

class MySwitchState extends State<MySwitchDemo> {
  var _isChecked = false;

  double currentPosition = 66.0;

  _handleSome(bool tryDe) {
    setState(() {
      _isChecked = tryDe;
    });
  }

  _handleSlider(double ah) {
    setState(() {
      currentPosition = ah;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: Utils.getAppBar('SwitchDemo'),
      body: Center(
          child: Column(
        children: <Widget>[
          Switch(
            value: _isChecked,
            onChanged: _handleSome,
          ),
          Slider(
            label: "进度",
            min: 0.0,
            max: 100.0,
            value: currentPosition,
            onChanged: _handleSlider,
          ),
        ],
      )),
    );
  }
}

//组合 控件
//CheckBox、Radio、Switch、的用法，但是这些组件一般不是单独使用的，一般会和Text、Icon或者其他的Widget结合使用。
//
//当然Flutter中为我们内置了多个相关的Widget，例如：
//
//CheckboxListTile、RadioListTile、SwitchListTile，当然这些Widget的用法类似于前面我们说过的ListTitle
// ，点击的时候 会触发整个事件

class MyCheckboxListTileDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MyListTileState();
  }
}

class MyListTileState extends State<MyCheckboxListTileDemo> {
  bool _checked = false;

  _handleChangeState(bool state) {
    setState(() {
      _checked = state;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: Utils.getAppBar('组合控件'),
      body: Center(
        child: CheckboxListTile(
          value: _checked,
          onChanged: _handleChangeState,
          title: Text('第一行文字'),
          subtitle: Text('第二行文字'),
          secondary: Icon(
            Icons.update,
            color: Colors.red,
          ),
        ),
      ),
    );
  }
}

class MyListPractice extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new MyListDemoState();
  }
}

class MyListDemoState extends State<MyListPractice> {
  bool _checkState = false;

  int _radioState = 0;
  bool _switchState = false;

  _handleCheckState(bool state) {
    setState(() {
      _checkState = state;
    });
  }

  _handleRadioState(int index) {
    setState(() {
      _radioState = index;
    });
  }

  _handleSwitchState(bool state) {
    setState(() {
      _switchState = state;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: Utils.getAppBar('Test'),
      body: Column(
        children: <Widget>[
          Container(
            child: CheckboxListTile(
              value: _checkState,
              onChanged: _handleCheckState,
              title: Text('新版本自动下载'),
              subtitle: Text('在wifi下可用'),
              secondary: Icon(
                Icons.update,
                color: Colors.blue,
              ),
            ),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(color: Colors.grey),
              ),
            ),
          ),
          Container(
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(color: Colors.grey)),
            ),
            child: Column(
              children: <Widget>[
                RadioListTile(
                  value: 0,
                  groupValue: _radioState,
                  onChanged: _handleRadioState,
                  title: Text(
                    '定时提醒间隔',
                  ),
                  subtitle: Text('10分钟'),
                  controlAffinity: ListTileControlAffinity.trailing,  //  控制圆形选择框的位置
                  secondary: Icon(
                    Icons.alarm,
                    color: Colors.blue,
                  ),
                ),
                RadioListTile(
                  value: 1,
                  groupValue: _radioState,
                  controlAffinity: ListTileControlAffinity.trailing,  //  控制圆形选择框的位置
                  onChanged: _handleRadioState,
                  title: Text(
                    '定时提醒间隔',
                  ),
                  subtitle: Text('30分钟'),
                  secondary: Icon(
                    Icons.alarm,
                    color: Colors.blue,
                  ),
                ),
                RadioListTile(
                  value: 2,
                  controlAffinity: ListTileControlAffinity.trailing,  //  控制圆形选择框的位置
                  groupValue: _radioState,
                  onChanged: _handleRadioState,
                  title: Text(
                    '定时提醒间隔',
                  ),
                  subtitle: Text('50分钟'),
                  secondary: Icon(
                    Icons.alarm,
                    color: Colors.blue,
                  ),
                ),
              ],
            ),
          ),
          SwitchListTile(
            value: _switchState,
            onChanged: _handleSwitchState,
            title: Text('新消息提醒'),
            secondary: Icon(
              Icons.message,
              color: Colors.blue,
            ),
          ),
        ],
      ),
    );
  }
}
